from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response
from dingxiang.utils import constants
# Create your views here.

from coupon.ser import get_user_coupon_list,get_user_enable_coupon_list

class CouponListView(APIView):
    permission_classes = [IsAuthenticated]

    def get(self,request):
        user_id = request.user.id
        coupon_list = get_user_coupon_list(user_id)
        return Response({"message":"优惠券列表获取成功","coupon":coupon_list})


class EnableCouponListView(APIView):

    permission_classes = [IsAuthenticated]

    def get(self,request):
        user_id = request.user.id
        data = get_user_enable_coupon_list(user_id)

        return Response({
            "message":"可用优惠券查询成功",
            "couponlist":data,
            "has_credit":request.user.credit,
            "credit_to_money":constants.CREDIT_TO_MONEY
        })



